package ar.com.tallerdos.smartdinner.sync;

import android.app.Activity;
import android.app.ProgressDialog;

public class GenericAsyncTask extends BaseAsyncTask {
    
    private Tarea tarea;
    protected Activity activity;
    protected ProgressDialog dialogoCargando;
    
    public GenericAsyncTask(Tarea t) {
	this.tarea = t;
	this.activity = null;
	this.dialogoCargando = null;
    }
    
    public GenericAsyncTask(Tarea t, Activity activity) {
	this.tarea = t;
	this.activity = activity;
	this.dialogoCargando = new ProgressDialog(activity);
    }

    @Override
    protected Integer doInBackground(Void... params) {
	return this.tarea.realizarTarea();
    }
    
    @Override
    protected void onPreExecute() {
	super.onPreExecute();
	if (activity != null) {
	    this.dialogoCargando.setMessage("\tCargando...");
	    this.dialogoCargando.show();	    
	}
    }
    
    @Override
    protected void onPostExecute(Integer result) {
        super.onPostExecute(result);
	if (this.activity != null) {
	    this.dialogoCargando.dismiss();
	}
	if (this.tarea != null) {
	    this.tarea.onPostExecute();
	}
    }
}
